<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/9/29 0029
 * Time: 9:16
 */
namespace app\wxapp\controller;

use app\BaseController;
use app\common\entity\Result;
use app\Request;
use app\wxapp\service\WechatUserService;
use think\facade\Cache;

class Login extends BaseController {

    public function login(Request $request){
        $code = $request->get("code");
        $service = new WechatUserService();
        try{
            $res = $service->login($code);
        }catch (\Exception $e){
            return Result::error($e->getMessage());
        }
        return Result::success($res);
    }


    public function thirdLogin(Request $request){
        $this->getPlayInfo();
//        $code = $request->param("code");
//        $api = "http://api.doctorsclass.com/api/mp/getSession?code=".$code;
//        $ch = curl_init();
//        curl_setopt($ch, CURLOPT_URL, $api);
//        curl_setopt($ch, CURLOPT_HEADER, 1);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//        curl_setopt($ch, CURLOPT_POST, 1);
//
//        //不知道为什么去掉这个在之前的项目中运行的好好的 这里就不行
//        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
//        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在
//
//        $res = curl_exec($ch);
//        var_dump($res);

        //$res = json_decode($res,true);
        //Cache::set("thirdSession",$res['session']);
        //return Result::success($res);
    }

    public function getPlayInfo(){
        $api = "http://api.doctorsclass.com/api/getPlayInfo?video_id=65c748b1feb342869dbfedca24968ddc";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $api);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, 1);

        //不知道为什么去掉这个在之前的项目中运行的好好的 这里就不行
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // 对认证证书来源的检查
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // 从证书中检查SSL加密算法是否存在

        $res = curl_exec($ch);
        var_dump($res);
    }

}